package com.flca.pstc42.dto;

import org.garret.perst.Persistent;

import com.flca.pstc42.util.PstcUtils;

public class PostcodesDto extends Persistent {

	private String postcode;
	private int van;
	private int tem;
	private int straatid;
	private int soort;
	private int lat;
	private int lng;
	
	public PostcodesDto() {
		super();
	}

	public PostcodesDto(String postcode, int van, int tem, int straatid,
			int coordid, int soort, int lat, int lng) 
	{
		super();
		this.postcode = postcode;
		this.van = van;
		this.tem = tem;
		this.straatid = straatid;
		this.soort = soort;
		this.lat = lat;
		this.lng = lng;
	}

	public String getPostcode() {
		return postcode;
	}
	

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}
	public int getVan() {
		return van;
	}
	public void setVan(int van) {
		this.van = van;
	}
	public int getTem() {
		return tem;
	}
	public void setTem(int tem) {
		this.tem = tem;
	}
	public int getStraatid() {
		return straatid;
	}
	public void setStraatid(int straatid) {
		this.straatid = straatid;
	}
	public int getSoort() {
		return soort;
	}
	public void setSoort(int soort) {
		this.soort = soort;
	}

	
	public int getLat() {
		return lat;
	}

	public void setLat(int lat) {
		this.lat = lat;
	}

	public int getLng() {
		return lng;
	}

	public void setLng(int lng) {
		this.lng = lng;
	}
	
	public static PostcodesDto make(String aCsvLine)
	{
		PostcodesDto result = new PostcodesDto();
		
		String tokens[] = aCsvLine.split(";");
		
		if (tokens.length == 7) {
			result.setPostcode(tokens[0]);
			result.setVan(Integer.parseInt(tokens[1]));
			result.setTem(Integer.parseInt(tokens[2]));
			result.setSoort(Integer.parseInt(tokens[3]));
			result.setStraatid(Integer.parseInt(tokens[4]));
			
			double d1 = Double.parseDouble(tokens[5]);
			double d2 = Double.parseDouble(tokens[6]);

			result.setLat((int) (d1 * PstcUtils.M));
			result.setLng((int) (d2 * PstcUtils.M));
		} else {
			System.out.println("bad line: " + aCsvLine);
		}
		
		return result;
	}	
	
}
